<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('物料信息')"/>
    <style>
        .deer-cell {
            border-color: #d3dce6;
            height: 46px;
            border-style: solid;
            z-index: 200000;
            text-align: center;
        }
        .deer-cell .deer-cell-title {
            line-height: 44px;
            font-weight: bold;
            color: #99a9bf;
            width: auto;
        }
        .searchBox{
            width: 50px;
            height: 32px;
            text-align: center;
            line-height: 32px;
            background-color: #409EFF;
            color: #FFFFFF;
            border-radius: 4px;
            display: inline-block;
            cursor: pointer;
        }
        .el-select{
            width: 177px;
        }
    </style>
</head>
<body>
<div class="container-div">
    <el-form label-width="100px" label-position="left" :model="domain" :rules="rules" ref="insertForm" class="demo-ruleForm" :inline="true">
        <el-divider content-position="left" style="margin-bottom: 20px">机台信息</el-divider>
        <div style="margin-left: 5%">
            <div style="display: inline-block">
                <el-form-item size="small" label="机台编码:" prop="deviceCode">
                    <el-input placeholder="请输入机台编码" size="small" v-model="domain.deviceCode"></el-input>
                </el-form-item>
            </div>
            <div style="display: inline-block">
                <el-form-item size="small" label="机台名称:" prop="itemName">
                    <el-input placeholder="请输入机台名称" size="small" v-model="domain.deviceName"></el-input>
                </el-form-item>
            </div>
        </div>
    </el-form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/wms/js/date.js}"></script>
<script type="text/javascript" charset="UTF-8">
    var prefix = ctx + "system/device"
    function submitHandler() {
        app.save();
    }
    var app = new Vue({
        el: '.container-div',
        data() {
            return {
                rules:{
                    itemCode: [
                        { required: true, message: '请输入物料编码', trigger: 'change' },
                    ],
                    height: [
                        { required: true, message: '请输入高度', trigger: 'change' },
                    ],
                },
                domain: {
                    deviceCode: '',
                    deviceName: ''
                },
                title: '',
                id: ''
            }
        },
        methods: {
            //关闭此页面
            closeModal: function(){
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            },
            save() {
                var that = this;
                this.$refs['insertForm'].validate((valid) => {
                    if (valid) {
                        console.log(that.domain)
                        if (that.title == '编辑') {
                            $.ajax({
                                cache: true,
                                url: prefix + "/edit",
                                type: 'POST',
                                async: false,
                                data: that.domain,
                                error: function (request) {
                                    $.modal.alertError("系统错误");
                                },
                                success: function (data) {
                                    if(data.code == 0){
                                        $.modal.msgReload(data.msg, "success")
                                    }else{
                                        $.modal.alertError(data.msg);
                                    }
                                }
                            })
                        } else {
                            $.ajax({
                                cache: true,
                                url: prefix + '/add',
                                type: 'POST',
                                async: false,
                                data: that.domain,
                                error: function (request) {
                                    $.modal.alertError("系统错误");
                                },
                                success: function (data) {
                                    if(data.code == 0){
                                        $.modal.msgReload(data.msg, "success")
                                    }else{
                                        $.modal.alertError(data.msg);
                                    }
                                }
                            })
                        }
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            }
        },
        created(){
            this.title = localStorage.getItem('jttitle');
            this.id = localStorage.getItem('/system/device/add');
            let that = this;
            if (this.title == '编辑') {
                $.ajax({
                    cache: true,
                    url: prefix + '/findItemById',
                    type: 'POST',
                    data: {
                        id: that.id
                    },
                    error: function (request) {
                        $.modal.alertError("系统错误");
                    },
                    success: function (data) {
                        console.log(data)
                        that.domain = data;
                    }
                })
            } else {
                that.domain = {
                    deviceCode: '',
                    deviceName: ''
                };
            }
        }
    })
</script>
</body>
</html>
